import axios from 'axios'
const request = axios.create({
  baseURL: 'http://localhost:3000',
  timeout: 6000
})

// 请求拦截
request.interceptors.request.use(
  config => {
    /* if(config.headers) {
      config.headers['X-Token'] = 'colud-music-app-token'
    } */
    
    return config
  }
)
// 响应拦截
request.interceptors.response.use(
  response => {
    const res =  response.data
    if(res.code !== 200) {
      return Promise.reject(new Error(res.message || 'Network Error'))
    } else {
      return response
    }
  }
)

export default request